<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<a href="add.php">注册</a>
<?php
require "redis.php";
if(!empty($_COOKIE['auth'])) {
    $id=$redis->get("auth:".$_COOKIE["auth"]);
    $name=$redis->hGet("user:$id","username");
?>
欢迎您,<?php echo $name?>
    <a href="logout.php">退出</a>
<?php
}else{
?>
<a href="login.php">登陆</a>
<?php
}
//用户总数
$count=$redis->lSize("uid");
//页大小
$page_size=3;
//当前页码
$page_num=(!empty($_GET['page']))?$_GET['page']:1;
//页总数
$page_count=ceil($count/$page_size);

$start=($page_num-1)*$page_size;
$end=($start+$page_size-1);
$ids=$redis->lRange("uid",$start,$end);
/*for($i=1;$i<=($redis->get("userid"));$i++){
    $data[]=$redis->hGetAll("user:{$i}");
}
$data=array_filter($data);*/

foreach($ids as $v){
    $data[]=$redis->hGetAll("user:$v");
}
?>
<table border="1" bordercolor="#a0c6e5" style="border-collapse:collapse;">
    <thead>
    <tr>
        <th>用户名</th>
        <th>年龄</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <?php foreach($data as $val){?>
        <tr>
            <td><?php echo $val["username"]?></td>
            <td><?php echo $val["age"]?></td>
            <td><a href="delete.php?id=<?php echo $val["uid"]?>">删除</a>|
                <a href="edit.php?id=<?php echo $val["uid"]?>">编辑</a>
                <?php if(!empty($_COOKIE["auth"])&&$id!=$val["uid"]){?>
                |<a href="addfans.php?id=<?php echo $val["uid"]?>&uid=<?php echo $id?>">关注</a>
                <?php }?>
            </td>
        </tr>
    <?php }?>
    <tr>
        <td colspan="4">
            <a href="?page=<?php if($page_num-1<=1){echo 1;}else{echo ($page_num-1);} ?>">上一页</a>
            <a href="?page=<?php if($page_num+1>=$page_count){echo $page_count;}else{echo ($page_num+1);} ?>">下一页</a>
            <a href="?page=<?php echo 1?>">首页</a>
            <a href="?page=<?php echo $page_count?>">尾页</a>
            当前<?php echo $page_num?>页
            总共<?php echo $page_count ?>页
            总共<?php echo $count ?>个用户
        </td>
    </tr>
    </tbody>
</table>
</body>
</html>

